<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            width: 250px;
            display: flex;
            flex-wrap: wrap;
        }

        li {

            width: 50px;
            height: 50px;
            margin: 5px 5px;
            background-color: #f00;
            list-style-type: none;
        }

        .class {
            background-color: #fff;
        }
    </style>
</head>

<body>
    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
    <script>
        let lis = document.getElementsByTagName("li");

        for (let index = 0; index < lis.length; index++) {
            lis[index].onclick = function () {
                let res = this.getAttribute("class");
                if (!res) {
                    // API:setAttribute 设置或修改元素的属性值
                    this.setAttribute("class", "click");
                    this.innerText = "座位已选";
                } else {
                    this.setAttribute("class", "");
                    this.innerText = "";
                }
            }
        }
    </script>
</body>

</html>